package com.xiliu.server.modules.basicdata.controller;

import com.xiliu.common.annotation.Log;
import com.xiliu.common.controller.BaseController;
import com.xiliu.common.enums.BusinessType;
import com.xiliu.common.page.TableDataInfo;
import com.xiliu.common.result.R;
import com.xiliu.server.modules.basicdata.entity.XlTopnav;
import com.xiliu.server.modules.basicdata.service.IXlTopnavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 导航表Controller
 * 
 * @author xiliu
 * @date 2022-11-28
 */
@RestController
@RequestMapping("/basic/topnav")
public class XlTopnavController extends BaseController {
    @Autowired
    private IXlTopnavService xlTopnavService;

    /**
     * 查询导航表列表
     */
    @PreAuthorize("@customSs.hasPermi('basic:topnav:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlTopnav xlTopnav) {
        startPage();
        List<XlTopnav> list = xlTopnavService.selectXlTopnavList(xlTopnav);
        return getDataTable(list);
    }

    /**
     * 获取导航表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('basic:topnav:query')")
    @GetMapping(value = "/{topnavId}")
    public R getInfo(@PathVariable("topnavId") Long topnavId) {
        return R.ok(xlTopnavService.selectXlTopnavById(topnavId));
    }

    /**
     * 新增导航表
     */
    @PreAuthorize("@customSs.hasPermi('basic:topnav:create')")
    @Log(title = "导航表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody XlTopnav xlTopnav) {
        boolean success = xlTopnavService.create(xlTopnav);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改导航表
     */
    @PreAuthorize("@customSs.hasPermi('basic:topnav:edit')")
    @Log(title = "导航表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{topnavId}")
    public R update(@PathVariable Long topnavId,  @RequestBody XlTopnav xlTopnav) {
        xlTopnav.setTopnavId(topnavId);
        boolean success = xlTopnavService.update(xlTopnav);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除导航表
     */
    @PreAuthorize("@customSs.hasPermi('basic:topnav:remove')")
    @Log(title = "导航表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topnavIds}")
    public R remove(@PathVariable Long[] topnavIds) {
        return R.ok(xlTopnavService.deleteXlTopnavByIds(topnavIds));
    }
}
